package com.ezjie.login.task;

import java.util.HashMap;
import java.util.Map;

import com.ezjie.baselib.core.http.HttpRequestCallBack;
import com.ezjie.login.InterfaceInfo.ServiceInterface;
import com.ezjie.login.core.http.HttpAPI;

import android.content.Context;

public class RegisterTask {

	private Context context;

	public RegisterTask(Context context) {
		this.context = context;
	}

	/**
	 * 注册
	 * 
	 * @param username
	 * @param password
	 * @param httpRequestCallBack
	 */
	public void doRegister(String nickname, String username, String password,
			HttpRequestCallBack httpRequestCallBack) {
		Map<String, String> params = new HashMap<String, String>();
		params.put("nick_name", nickname);
		params.put("email", username);
		params.put("password", password);
		HttpAPI.getInstance(context,ServiceInterface.API_USER_BASE).doPostRequest(
				ServiceInterface.OPT_REG, params,
				httpRequestCallBack);
	}
	/**
	 * 发送短信验证码
	 * @param mobile
	 * @param type
	 * @param httpRequestCallBack
	 */
	public void sendSmsCode(String mobile,String type,HttpRequestCallBack httpRequestCallBack){
		Map<String, String> params = new HashMap<String, String>();
		params.put("mobile", mobile);
		params.put("type", type);
		
		HttpAPI.getInstance(context,ServiceInterface.API_USER_BASE).doPostRequest(
				ServiceInterface.OPT_SEND_SMS_CODE, params,
				httpRequestCallBack);
	}
	/**
	 * 根据whatcode 判断是 发短信验证码还是  邮箱
	 * @param whatCode 0 短信  1邮箱
	 * @param mobile
	 * @param type
	 * @param httpRequestCallBack
	 */
	public void sendCodeByWhat(int whatCode,String mobile,String type,HttpRequestCallBack httpRequestCallBack){
		Map<String, String> params = new HashMap<String, String>();
		String path = "";
		params.put("from", "1");//定位是从找回密码 发送的验证码。
		if (whatCode == 0) {
			params.put("mobile", mobile);
			params.put("type", type);
			path = ServiceInterface.OPT_SEND_SMS_CODE;
		}else {
			params.put("email", mobile);
			path = ServiceInterface.OPT_SEND_EMAIL_CODE;
		}
		
		
		HttpAPI.getInstance(context,ServiceInterface.API_USER_BASE).doPostRequest(
				path, params,
				httpRequestCallBack);
	}
	
	/**
	 * 检查手机短信验证码
	 * @param mobile
	 * @param type
	 * @param httpRequestCallBack
	 */
	public void checksmsCode(String mobile,String verify_code,HttpRequestCallBack httpRequestCallBack){
		Map<String, String> params = new HashMap<String, String>();
		params.put("mobile", mobile);
		params.put("verify_code", verify_code);
		
		HttpAPI.getInstance(context,ServiceInterface.API_USER_BASE).doPostRequest(
				ServiceInterface.OPT_CHECK_SMS_CODE, params,
				httpRequestCallBack);
	}
	public void checkCodeByWhat(int whatCode,String mobile,String verify_code,HttpRequestCallBack httpRequestCallBack){
		Map<String, String> params = new HashMap<String, String>();
		String path = "";
		if (whatCode == 0) {
			params.put("mobile", mobile);
			params.put("verify_code", verify_code);
			path = ServiceInterface.OPT_CHECK_SMS_CODE;
		}else {
			params.put("email", mobile);
			params.put("verify_code", verify_code);
			path = ServiceInterface.OPT_CHECK_EMAIL_CODE;
		}
		
		
		HttpAPI.getInstance(context,ServiceInterface.API_USER_BASE).doPostRequest(
				path, params,
				httpRequestCallBack);
	}
	
	public void doReg(String mobile,String password,String verify_code,String nick_name,
			HttpRequestCallBack httpRequestCallBack){
		Map<String, String> params = new HashMap<String, String>();
		params.put("mobile", mobile);
		params.put("password", password);
		params.put("verify_code", verify_code);
		params.put("nick_name", nick_name);
		
		HttpAPI.getInstance(context,ServiceInterface.API_USER_BASE).doPostRequest(
				ServiceInterface.OPT_USER_REG, params,
				httpRequestCallBack);
	}
	/**
	 * 重置密码
	 * @param new_password
	 * @param verify_code
	 * @param mobile
	 * @param email
	 * @param httpRequestCallBack
	 */
	public void resetPass(String new_password,String verify_code,String mobile,String email,
			HttpRequestCallBack httpRequestCallBack){
		Map<String, String> params = new HashMap<String, String>();
		params.put("new_password", new_password);
		params.put("verify_code",verify_code);
		params.put("mobile",mobile);
		params.put("email",email);
		
		HttpAPI.getInstance(context,ServiceInterface.API_USER_BASE).doPostRequest(
				ServiceInterface.OPT_USER_RESETPASSWORD, params,
				httpRequestCallBack);
	}

}
